package com.lqian.stream.flatmap;

import com.lqian.paging.User;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class Test {

    public static void main(String[] args) {
        List<User> userList1 = new ArrayList<>();
        userList1.add(new User(1, "小文", "123456", 16, 1, 20000d));
        userList1.add(new User(2, "老季", "123456", 22, 1, 100000d));
        userList1.add(new User(3, "怪咖", "123456", 13, 1, 89557d));
        userList1.add(new User(4, "小六", "123456", 26, 1, 78000d));
        userList1.add(new User(5, "小刘", "123456", 46, 1, 58000d));

        List<User> userList2 = new ArrayList<>();
        userList2.add(new User(22, "小文", "123456", 16, 1, 20000d));
        userList2.add(new User(2, "老季", "123456", 22, 1, 100000d));
        userList2.add(new User(3, "怪咖", "123456", 13, 1, 89557d));
        userList2.add(new User(4, "小六", "123456", 26, 1, 78000d));
        userList2.add(new User(5, "小刘", "123456", 46, 1, 58000d));


        //并集
//        List<Integer> allUserList=
//                Stream.of(userList1, userList2)
//                        .flatMap(u -> u.stream())
//                        .map(user -> user.getAge())
//                        .distinct()
//                        .collect(Collectors.toList());
//        allUserList.forEach(System.out::println);

        //交集
//        List<User> sameUserList = userList2.stream()
//                //.filter(user -> userList1.contains(user))
//                .filter(userList1::contains)
//                .collect(Collectors.toList());
//        sameUserList.forEach(user -> System.out.println(user));


        //差集
        List<User> diffUserList2 = userList2.stream()
                //.filter(user -> userList1.contains(user))
                .filter(user -> !userList1.contains(user))
                .collect(Collectors.toList());
        diffUserList2.forEach(user -> System.out.println(user));

    }
}
